import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

import javax.swing.*;

public class MainFrame extends JFrame implements ActionListener, MouseListener{

	MorrisDraw md = new MorrisDraw();
//	MorrisElement me = new MorrisElement();
	JPanel panelPlayer1 = new JPanel();
	JPanel panelPlayer2 = new JPanel();
	JPanel panelSouth = new JPanel();
	Container contentPane;
	
	//Player1's components
	JLabel player1Label = new JLabel("PLAYER 1");
	JLabel remainedLabelPlayer1 = new JLabel("Pieces remained to place: ");
	JLabel onBoardLabelPlayer1 = new JLabel("Pieces on the board: ");
	JLabel lostLabelPlayer1 = new JLabel("Pieces lost in this game: ");
	JTextField remainedTextPlayer1 = new JTextField(5);
	JTextField onBoardTextPlayer1 = new JTextField(5);
	JTextField lostTextPlayer1 = new JTextField(5);
	JLabel morrisPlayer1 = new JLabel("MORRIS!");
	JLabel illegalMovePlayer1 = new JLabel("ILLEGAL MOVE");
	JLabel winPlayer1 = new JLabel("   WIN :)   ");
	JLabel lostPlayer1 = new JLabel("   LOST :(   ");
	JPanel remainedPlayer1 = new JPanel();
	JPanel onBoardPlayer1 = new JPanel();
	JPanel lostPanelPlayer1 = new JPanel();
	JPanel winLostPlayer1 = new JPanel();
	
	//Player2's components
	JLabel player2Label = new JLabel("PLAYER 2");
	JLabel remainedLabelPlayer2 = new JLabel("Pieces remained to place: ");
	JLabel onBoardLabelPlayer2 = new JLabel("Pieces on the board: ");
	JLabel lostLabelPlayer2 = new JLabel("Pieces lost in this game: ");
	JTextField remainedTextPlayer2 = new JTextField(5);
	JTextField onBoardTextPlayer2 = new JTextField(5);
	JTextField lostTextPlayer2 = new JTextField(5);
	JLabel morrisPlayer2 = new JLabel("MORRIS!");
	JLabel illegalMovePlayer2 = new JLabel("ILLEGAL MOVE");
	JLabel winPlayer2 = new JLabel("   WIN :)   ");
	JLabel lostPlayer2 = new JLabel("   LOST :(   ");
	JPanel remainedPlayer2 = new JPanel();
	JPanel onBoardPlayer2 = new JPanel();
	JPanel lostPanelPlayer2 = new JPanel();
	JPanel winLostPlayer2 = new JPanel();
	
	
	//again and start buttons, label
	JButton againButton = new JButton("Again");
	JButton exitButton = new JButton("Exit");
	JLabel messageLabel = new JLabel("message");
	JPanel panelButtons = new JPanel();
	JPanel messagePanel = new JPanel();
	
	int mouseX, mouseY;
	
	public MainFrame(){
		super("Nine men's morris");
		
		contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());
		contentPane.add(panelPlayer1, "West");
		contentPane.add(panelPlayer2, "East");
		contentPane.add(panelSouth, "South");
		contentPane.add(md, "Center");
		
		GridLayout grid7_1 = new GridLayout(7,1,10,10);
		
		//adding player 1's components to the panel
		panelPlayer1.setLayout(grid7_1);
		panelPlayer1.add(player1Label);
		panelPlayer1.add(player1Label);
		FlowLayout flow = new FlowLayout(FlowLayout.CENTER);
		remainedPlayer1.setLayout(flow);
		panelPlayer1.add(remainedPlayer1);
		remainedPlayer1.add(remainedLabelPlayer1);
		remainedPlayer1.add(remainedTextPlayer1);
		panelPlayer1.add(onBoardPlayer1);
		onBoardPlayer1.setLayout(flow);
		onBoardPlayer1.add(onBoardLabelPlayer1);
		onBoardPlayer1.add(onBoardTextPlayer1);
		panelPlayer1.add(lostPanelPlayer1);
		lostPanelPlayer1.setLayout(flow);
		lostPanelPlayer1.add(lostLabelPlayer1);
		lostPanelPlayer1.add(lostTextPlayer1);
		panelPlayer1.add(morrisPlayer1);
		panelPlayer1.add(illegalMovePlayer1);
		panelPlayer1.add(winLostPlayer1);
		winLostPlayer1.setLayout(flow);
		winLostPlayer1.add(winPlayer1);
		winLostPlayer1.add(lostPlayer1);
		//end of adding player 1's components
		
		//adding player 2's components
		panelPlayer2.setLayout(grid7_1);
		panelPlayer2.add(player2Label);
		remainedPlayer2.setLayout(flow);
		panelPlayer2.add(remainedPlayer2);
		remainedPlayer2.add(remainedLabelPlayer2);
		remainedPlayer2.add(remainedTextPlayer2);
		panelPlayer2.add(onBoardPlayer2);
		onBoardPlayer2.setLayout(flow);
		onBoardPlayer2.add(onBoardLabelPlayer2);
		onBoardPlayer2.add(onBoardTextPlayer2);
		panelPlayer2.add(lostPanelPlayer2);
		lostPanelPlayer2.setLayout(flow);
		lostPanelPlayer2.add(lostLabelPlayer2);
		lostPanelPlayer2.add(lostTextPlayer2);
		panelPlayer2.add(morrisPlayer2);
		panelPlayer2.add(illegalMovePlayer2);
		panelPlayer2.add(winLostPlayer2);
		winLostPlayer2.setLayout(flow);
		winLostPlayer2.add(winPlayer2);
		winLostPlayer2.add(lostPlayer2);
		//end of adding player 2's components
		
		//adding "again" and "exit" buttons
		GridLayout grid = new GridLayout(2,1,10,10);
		panelSouth.setLayout(grid);
		panelButtons.setLayout(flow);
		panelSouth.add(panelButtons);
		panelButtons.add(againButton);
		panelButtons.add(exitButton);
		panelSouth.add(messagePanel);
		messagePanel.setLayout(flow);
		messagePanel.add(messageLabel);
		
		setVisible(true);
		
		//disabling the unnecessary parts
		remainedTextPlayer1.setEnabled(false);
		onBoardTextPlayer1.setEnabled(false);
		lostTextPlayer1.setEnabled(false);
		remainedTextPlayer2.setEnabled(false);
		onBoardTextPlayer2.setEnabled(false);
		lostTextPlayer2.setEnabled(false);
		morrisPlayer1.setEnabled(false);
		morrisPlayer2.setEnabled(false);
		illegalMovePlayer1.setEnabled(false);
		illegalMovePlayer2.setEnabled(false);
		winPlayer1.setEnabled(false);
		lostPlayer1.setEnabled(false);
		winPlayer2.setEnabled(false);
		lostPlayer2.setEnabled(false);
		remainedTextPlayer1.setEnabled(false);
		remainedTextPlayer2.setEnabled(false);
		onBoardTextPlayer1.setEnabled(false);
		onBoardTextPlayer2.setEnabled(false);
		lostTextPlayer1.setEnabled(false);
		lostTextPlayer2.setEnabled(false);
		player2Label.setEnabled(false);
		remainedTextPlayer1.setText("9");
		remainedTextPlayer2.setText("9");
		onBoardTextPlayer1.setText("0");
		onBoardTextPlayer2.setText("0");
		lostTextPlayer1.setText("0");
		lostTextPlayer2.setText("0");
		
		
		againButton.addActionListener(this);
		exitButton.addActionListener(this);
		md.addMouseListener(this);
		
	}
	
	//ActionListener's methods
	
	public void actionPerformed(ActionEvent ev){
		JButton source = (JButton) ev.getSource();
		if (source == exitButton){
			dispose();
		}
		if (source == againButton){
			repaint();
		}
			
	}
	
	//MouseListener's methods
	
	public void mouseEntered(MouseEvent ev){}
	public void mouseExited(MouseEvent ev){}
	public void mousePressed(MouseEvent ev){}
	public void mouseReleased(MouseEvent ev){}
	public void mouseClicked(MouseEvent ev){
		mouseX = ev.getX();
		mouseY = ev.getY();
		boolean forward = false;
		Element nowElement = null;
		boolean morris = false;
	//	int m = -1, n = -1;
		
		for (int i=0; i<=6; i++){
			for (int j=0; j<=6; j++){
				int a = md.me.element[i][j].getX()+13;
				int b = md.me.element[i][j].getY()+13;;
				if (((mouseX - a)*(mouseX - a) + (mouseY - b)* (mouseY - b) - 13*13)<=0){
					forward = true;
					//nowElement = md.me.element[i][j];
					if (player1Label.isEnabled()){
						md.me.element[i][j].setPlayer("red");
						int nr = Integer.parseInt(remainedTextPlayer1.getText());
						nr--;
						remainedTextPlayer1.setText(Integer.toString(nr));
					}
					else {
						md.me.element[i][j].setPlayer("yellow");
						int nr = Integer.parseInt(remainedTextPlayer2.getText());
						nr--;
						remainedTextPlayer2.setText(Integer.toString(nr));
					}
					nowElement = md.me.element[i][j];

				}
				//System.out.println("i= " + i + " j= " + j + "   " + md.me.element[i][j].getPlayer() + " " + md.me.element[i][j].getIsInMorris());
				if (isMorris(nowElement, i, j, true)){
					System.out.println("malom");
				}
			}
		}

		System.out.println("x: " + mouseX + " y: " + mouseY);
		repaint();
		
		if (morris)
			if (player1Label.isEnabled())
				morrisPlayer1.setEnabled(true);
			else morrisPlayer2.setEnabled(true);
		
		if (forward == true){
			if (player1Label.isEnabled()){
				player2Label.setEnabled(true);
				player1Label.setEnabled(false);
				}
			else{player2Label.setEnabled(false);
				player1Label.setEnabled(true);
				}
			}
	}
	
	
	public boolean isMorris(Element elem, int m, int n, boolean state){
		boolean value = false;
		String actualColor = elem.getPlayer();
		
		if (actualColor != "blue"){
			// (0,0)
			if (m==0 && n==0){ //(0,0), (0,3), (0,6)
				if (actualColor.equals(md.me.element[0][3].getPlayer())&& actualColor.equals(md.me.element[0][6].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[0][6].setIsInMorris(state);
				} //(0,0), (3,0), (6,0)
				if (actualColor.equals(md.me.element[3][0].getPlayer())&& actualColor.equals(md.me.element[6][0].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[6][0].setIsInMorris(state);
				}
			}
			// (3,0)
			if (m==3 && n==0){ //(0,0), (3,0), (6,0)
				if (actualColor.equals(md.me.element[0][0].getPlayer())&& actualColor.equals(md.me.element[6][0].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[6][0].setIsInMorris(state);
				} //(3,0), (3,1), (3,2)
				if (actualColor.equals(md.me.element[3][1].getPlayer())&& actualColor.equals(md.me.element[3][2].getPlayer())){
					value = true;
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
				}
			} //(6,0)
			if (m==6 && n==0){ //(0,0), (3,0), (6,0)
				if (actualColor.equals(md.me.element[0][0].getPlayer())&& actualColor.equals(md.me.element[3][0].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[6][0].setIsInMorris(state);
				} //(6,0), (6,3), (6,6)
				if (actualColor.equals(md.me.element[6][3].getPlayer())&& actualColor.equals(md.me.element[6][6].getPlayer())){
					value = true;
					md.me.element[6][0].setIsInMorris(state);
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[6][6].setIsInMorris(state);
				}
			}//(6,3)
			if (m==6 && n==3){ //(6,0), (6,3), (6,6)
				if (actualColor.equals(md.me.element[6][0].getPlayer())&& actualColor.equals(md.me.element[6][6].getPlayer())){
					value = true;
					md.me.element[6][0].setIsInMorris(state);
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[6][6].setIsInMorris(state);
				} //(6,3), (5,3), (4,3)
				if (actualColor.equals(md.me.element[5][3].getPlayer())&& actualColor.equals(md.me.element[4][3].getPlayer())){
					value = true;
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[5][3].setIsInMorris(state);
					md.me.element[4][3].setIsInMorris(state);
				}
			} //(6,6)
			if (m==6 && n==6){ //(6,0), (6,3), (6,6)
				if (actualColor.equals(md.me.element[6][0].getPlayer())&& actualColor.equals(md.me.element[6][3].getPlayer())){
					value = true;
					md.me.element[6][0].setIsInMorris(state);
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[6][6].setIsInMorris(state);
				} //(6,6), (3,6), (0,6)
				if (actualColor.equals(md.me.element[3][6].getPlayer())&& actualColor.equals(md.me.element[0][6].getPlayer())){
					value = true;
					md.me.element[6][6].setIsInMorris(state);
					md.me.element[3][6].setIsInMorris(state);
					md.me.element[0][6].setIsInMorris(state);
				}
			} //(3,6)
			if (m==3 && n==6){ //(6,6), (3,6), (0,6)
				if (actualColor.equals(md.me.element[6][6].getPlayer())&& actualColor.equals(md.me.element[0][6].getPlayer())){
					value = true;
					md.me.element[6][6].setIsInMorris(state);
					md.me.element[3][6].setIsInMorris(state);
					md.me.element[0][6].setIsInMorris(state);
				} //(3,6), (3,5), (3,4)
				if (actualColor.equals(md.me.element[3][5].getPlayer())&& actualColor.equals(md.me.element[3][4].getPlayer())){
					value = true;
					md.me.element[3][6].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[3][4].setIsInMorris(state);
				}
			}//(0,6)
			if (m==0 && n==6){ //(0,6), (3,6), (6,6)
				if (actualColor.equals(md.me.element[3][6].getPlayer())&& actualColor.equals(md.me.element[6][6].getPlayer())){
					value = true;
					md.me.element[0][6].setIsInMorris(state);
					md.me.element[3][6].setIsInMorris(state);
					md.me.element[6][6].setIsInMorris(state);
				} //(0,0), (0,3), (0,6)
				if (actualColor.equals(md.me.element[0][0].getPlayer())&& actualColor.equals(md.me.element[0][3].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[0][6].setIsInMorris(state);
				}
			}//(0,3)
			if (m==0 && n==3){ //(0,0), (0,3), (0,6)
				if (actualColor.equals(md.me.element[0][0].getPlayer())&& actualColor.equals(md.me.element[0][6].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[0][6].setIsInMorris(state);
				} //(0,3), (1,3), (2,3)
				if (actualColor.equals(md.me.element[3][1].getPlayer())&& actualColor.equals(md.me.element[3][2].getPlayer())){
					value = true;
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[1][3].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
				}
			}//(1,1)
			if (m==1 && n==1){ //(1,1), (3,1), (5,1)
				if (actualColor.equals(md.me.element[3][1].getPlayer())&& actualColor.equals(md.me.element[5][1].getPlayer())){
					value = true;
					md.me.element[1][1].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[5][1].setIsInMorris(state);
				} //(1,1), (1,3), (1,5)
				if (actualColor.equals(md.me.element[1][3].getPlayer())&& actualColor.equals(md.me.element[1][5].getPlayer())){
					value = true;
					md.me.element[1][1].setIsInMorris(state);
					md.me.element[1][3].setIsInMorris(state);
					md.me.element[1][5].setIsInMorris(state);
				}
			}//(3,1)
			if (m==3 && n==1){ //(1,1), (3,1), (5,1)
				if (actualColor.equals(md.me.element[0][0].getPlayer())&& actualColor.equals(md.me.element[6][0].getPlayer())){
					value = true;
					md.me.element[1][1].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[5][1].setIsInMorris(state);
				} //(3,0), (3,1), (3,2)
				if (actualColor.equals(md.me.element[3][0].getPlayer())&& actualColor.equals(md.me.element[3][2].getPlayer())){
					value = true;
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
				}
			}//(5,1)
			if (m==5 && n==1){ //(1,1), (3,1), (5,1)
				if (actualColor.equals(md.me.element[1][1].getPlayer())&& actualColor.equals(md.me.element[3][1].getPlayer())){
					value = true;
					md.me.element[1][1].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[5][1].setIsInMorris(state);
				} //(5,1), (5,3), (5,5)
				if (actualColor.equals(md.me.element[5][2].getPlayer())&& actualColor.equals(md.me.element[5][5].getPlayer())){
					value = true;
					md.me.element[5][1].setIsInMorris(state);
					md.me.element[5][3].setIsInMorris(state);
					md.me.element[5][5].setIsInMorris(state);
				}
			}//(5,3)
			if (m==5 && n==3){ //(5,1), (5,3), (5,5)
				if (actualColor.equals(md.me.element[5][1].getPlayer())&& actualColor.equals(md.me.element[5][5].getPlayer())){
					value = true;
					md.me.element[5][1].setIsInMorris(state);
					md.me.element[5][3].setIsInMorris(state);
					md.me.element[5][5].setIsInMorris(state);
				} //(6,3), (5,3), (4,3)
				if (actualColor.equals(md.me.element[6][3].getPlayer())&& actualColor.equals(md.me.element[4][3].getPlayer())){
					value = true;
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[5][3].setIsInMorris(state);
					md.me.element[4][3].setIsInMorris(state);
				}
			}//(5,5)
			if (m==5 && n==5){ //(5,1), (5,3), (5,5)
				if (actualColor.equals(md.me.element[5][1].getPlayer())&& actualColor.equals(md.me.element[5][3].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[6][0].setIsInMorris(state);
				} //(1,5), (3,5), (5,5)
				if (actualColor.equals(md.me.element[1][5].getPlayer())&& actualColor.equals(md.me.element[3][5].getPlayer())){
					value = true;
					md.me.element[1][5].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[5][5].setIsInMorris(state);
				}
			}//(3,5)
			if (m==3 && n==5){ //(1,5), (3,5), (5,5)
				if (actualColor.equals(md.me.element[1][5].getPlayer())&& actualColor.equals(md.me.element[5][5].getPlayer())){
					value = true;
					md.me.element[1][5].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[5][5].setIsInMorris(state);
				} //(3,4), (3,5), (3,6)
				if (actualColor.equals(md.me.element[3][4].getPlayer())&& actualColor.equals(md.me.element[3][6].getPlayer())){
					value = true;
					md.me.element[3][4].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[3][6].setIsInMorris(state);
				}
			}//(1,5)
			if (m==1 && n==5){ //(1,1), (1,3), (1,5)
				if (actualColor.equals(md.me.element[1][1].getPlayer())&& actualColor.equals(md.me.element[1][3].getPlayer())){
					value = true;
					md.me.element[1][1].setIsInMorris(state);
					md.me.element[1][3].setIsInMorris(state);
					md.me.element[1][5].setIsInMorris(state);
				} //(1,5), (3,5), (5,5)
				if (actualColor.equals(md.me.element[3][5].getPlayer())&& actualColor.equals(md.me.element[5][5].getPlayer())){
					value = true;
					md.me.element[1][5].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[5][5].setIsInMorris(state);
				}
			}//(1,3)
			if (m==1 && n==3){ //(1,1), (1,3), (1,5)
				if (actualColor.equals(md.me.element[1][1].getPlayer())&& actualColor.equals(md.me.element[1][5].getPlayer())){
					value = true;
					md.me.element[0][0].setIsInMorris(state);
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[6][0].setIsInMorris(state);
				} //(0,3), (1,3), (2,3)
				if (actualColor.equals(md.me.element[0][3].getPlayer())&& actualColor.equals(md.me.element[2][3].getPlayer())){
					value = true;
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[1][3].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
				}
			}//(2,2)
			if (m==2 && n==2){ //(2,2), (2,3), (2,4)
				if (actualColor.equals(md.me.element[2][3].getPlayer())&& actualColor.equals(md.me.element[2][4].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
					md.me.element[2][4].setIsInMorris(state);
				} //(2,2), (3,2), (4,2)
				if (actualColor.equals(md.me.element[3][2].getPlayer())&& actualColor.equals(md.me.element[4][2].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
					md.me.element[4][2].setIsInMorris(state);
				}
			}//(3,2)
			if (m==3 && n==2){ //(2,2), (3,2), (4,2)
				if (actualColor.equals(md.me.element[2][2].getPlayer())&& actualColor.equals(md.me.element[4][2].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
					md.me.element[4][2].setIsInMorris(state);
				} //(3,0), (3,1), (3,2)
				if (actualColor.equals(md.me.element[3][0].getPlayer())&& actualColor.equals(md.me.element[3][1].getPlayer())){
					value = true;
					md.me.element[3][0].setIsInMorris(state);
					md.me.element[3][1].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
				}
			}//(4,2)
			if (m==4 && n==2){ //(2,2), (3,2), (4,2)
				if (actualColor.equals(md.me.element[2][2].getPlayer())&& actualColor.equals(md.me.element[3][2].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[3][2].setIsInMorris(state);
					md.me.element[4][2].setIsInMorris(state);
				} //(4,2), (4,3), (4,4)
				if (actualColor.equals(md.me.element[4][3].getPlayer())&& actualColor.equals(md.me.element[4][4].getPlayer())){
					value = true;
					md.me.element[4][2].setIsInMorris(state);
					md.me.element[4][3].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				}
			}//(4,3)
			if (m==4 && n==3){ //(4,2), (4,3), (4,4)
				if (actualColor.equals(md.me.element[4][2].getPlayer())&& actualColor.equals(md.me.element[4][4].getPlayer())){
					value = true;
					md.me.element[4][2].setIsInMorris(state);
					md.me.element[4][3].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				} //(6,3), (5,3), (4,3)
				if (actualColor.equals(md.me.element[6][3].getPlayer())&& actualColor.equals(md.me.element[5][3].getPlayer())){
					value = true;
					md.me.element[6][3].setIsInMorris(state);
					md.me.element[5][3].setIsInMorris(state);
					md.me.element[4][3].setIsInMorris(state);
				}
			}//(4,4)
			if (m==4 && n==4){ //(4,2), (4,3), (4,4)
				if (actualColor.equals(md.me.element[4][2].getPlayer())&& actualColor.equals(md.me.element[4][3].getPlayer())){
					value = true;
					md.me.element[4][2].setIsInMorris(state);
					md.me.element[4][2].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				} //(2,4), (3,4), (4,4)
				if (actualColor.equals(md.me.element[2][4].getPlayer())&& actualColor.equals(md.me.element[3][4].getPlayer())){
					value = true;
					md.me.element[2][4].setIsInMorris(state);
					md.me.element[3][4].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				}
			}//(3,4)
			if (m==3 && n==4){ //(2,4), (3,4), (4,4)
				if (actualColor.equals(md.me.element[2][4].getPlayer())&& actualColor.equals(md.me.element[4][4].getPlayer())){
					value = true;
					md.me.element[2][4].setIsInMorris(state);
					md.me.element[3][4].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				} //(3,4), (3,5), (3,6)
				if (actualColor.equals(md.me.element[3][5].getPlayer())&& actualColor.equals(md.me.element[3][6].getPlayer())){
					value = true;
					md.me.element[3][4].setIsInMorris(state);
					md.me.element[3][5].setIsInMorris(state);
					md.me.element[3][6].setIsInMorris(state);
				}
			}//(2,4)
			if (m==2 && n==4){ //(2,4), (3,4), (4,4)
				if (actualColor.equals(md.me.element[3][4].getPlayer())&& actualColor.equals(md.me.element[4][4].getPlayer())){
					value = true;
					md.me.element[2][4].setIsInMorris(state);
					md.me.element[3][4].setIsInMorris(state);
					md.me.element[4][4].setIsInMorris(state);
				} //(2,2), (2,3), (2,4)
				if (actualColor.equals(md.me.element[2][2].getPlayer())&& actualColor.equals(md.me.element[2][3].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
					md.me.element[2][4].setIsInMorris(state);
				}
			}//(2,3)
			if (m==2 && n==3){ //(2,2), (2,3), (2,4)
				if (actualColor.equals(md.me.element[2][2].getPlayer())&& actualColor.equals(md.me.element[2][4].getPlayer())){
					value = true;
					md.me.element[2][2].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
					md.me.element[2][4].setIsInMorris(state);
				} //(0,3), (1,3), (2,3)
				if (actualColor.equals(md.me.element[0][3].getPlayer())&& actualColor.equals(md.me.element[1][3].getPlayer())){
					value = true;
					md.me.element[0][3].setIsInMorris(state);
					md.me.element[1][3].setIsInMorris(state);
					md.me.element[2][3].setIsInMorris(state);
				}
			}
		}	
		return value;
	}
	
	public boolean areNeighbours(int x1, int y1, int x2, int y2){
		boolean value = false;
		
		if (((x1==0)&&(y1==0)&&(x2==0)&&(y2==3))||((x1==0)&&(y1==3)&&(x2==0)&&(y2==0))) //(0,0), (0,3)
				value = true;
		else if (((x1==0)&&(y1==3)&&(x2==0)&&(y2==6))||((x1==0)&&(y1==6)&&(x2==0)&&(y2==3))) //(0,3), (0,6)
			value = true;
		else if (((x1==1)&&(y1==1)&&(x2==1)&&(y2==3))||((x1==1)&&(y1==3)&&(x2==1)&&(y2==1))) //(1,1), (1,3)
			value = true;
		else if (((x1==1)&&(y1==3)&&(x2==1)&&(y2==5))||((x1==1)&&(y1==5)&&(x2==1)&&(y2==3))) //(1,3), (1,5)
			value = true;
		else if (((x1==2)&&(y1==2)&&(x2==2)&&(y2==3))||((x1==2)&&(y1==3)&&(x2==2)&&(y2==2))) //(2,2), (2,3)
			value = true;
		else if (((x1==2)&&(y1==3)&&(x2==2)&&(y2==4))||((x1==2)&&(y1==4)&&(x2==2)&&(y2==3))) //(2,3), (2,4)
			value = true;
		else if (((x1==3)&&(y1==0)&&(x2==3)&&(y2==1))||((x1==3)&&(y1==1)&&(x2==3)&&(y2==0))) //(3,0), (3,1)
			value = true;
		else if (((x1==3)&&(y1==1)&&(x2==3)&&(y2==2))||((x1==3)&&(y1==2)&&(x2==3)&&(y2==1))) //(3,1), (3,2)
			value = true;
		else if (((x1==3)&&(y1==4)&&(x2==3)&&(y2==5))||((x1==3)&&(y1==5)&&(x2==3)&&(y2==4))) //(3,4), (3,5)
			value = true;
		else if (((x1==3)&&(y1==5)&&(x2==3)&&(y2==6))||((x1==3)&&(y1==6)&&(x2==3)&&(y2==5))) //(3,5), (3,6)
			value = true;
		else if (((x1==4)&&(y1==2)&&(x2==4)&&(y2==3))||((x1==4)&&(y1==3)&&(x2==4)&&(y2==2))) //(4,2), (4,3)
			value = true;
		else if (((x1==4)&&(y1==3)&&(x2==4)&&(y2==4))||((x1==4)&&(y1==4)&&(x2==4)&&(y2==3))) //(4,3), (4,4)
			value = true;
		else if (((x1==5)&&(y1==1)&&(x2==5)&&(y2==3))||((x1==5)&&(y1==3)&&(x2==5)&&(y2==1))) //(5,1), (5,3)
			value = true;
		else if (((x1==5)&&(y1==3)&&(x2==5)&&(y2==5))||((x1==5)&&(y1==5)&&(x2==5)&&(y2==3))) //(5,3), (5,5)
			value = true;
		else if (((x1==6)&&(y1==0)&&(x2==6)&&(y2==3))||((x1==6)&&(y1==3)&&(x2==6)&&(y2==0))) //(6,0), (6,3)
			value = true;
		else if (((x1==6)&&(y1==3)&&(x2==6)&&(y2==6))||((x1==6)&&(y1==6)&&(x2==6)&&(y2==3))) //(6,3), (6,6)
			value = true;
		else if (((x1==0)&&(y1==0)&&(x2==3)&&(y2==0))||((x1==3)&&(y1==0)&&(x2==0)&&(y2==0))) //(0,0), (3,0)
			value = true;
		else if (((x1==3)&&(y1==0)&&(x2==6)&&(y2==0))||((x1==6)&&(y1==0)&&(x2==3)&&(y2==0))) //(3,0), (6,0)
			value = true;
		else if (((x1==1)&&(y1==1)&&(x2==3)&&(y2==1))||((x1==3)&&(y1==1)&&(x2==1)&&(y2==1))) //(1,1), (3,1)
			value = true;
		else if (((x1==3)&&(y1==1)&&(x2==5)&&(y2==1))||((x1==5)&&(y1==1)&&(x2==3)&&(y2==1))) //(3,1), (5,1)
			value = true;
		else if (((x1==2)&&(y1==2)&&(x2==3)&&(y2==2))||((x1==3)&&(y1==2)&&(x2==2)&&(y2==2))) //(2,2), (3,2)
			value = true;
		else if (((x1==3)&&(y1==2)&&(x2==4)&&(y2==2))||((x1==4)&&(y1==2)&&(x2==3)&&(y2==2))) //(3,2), (4,2)
			value = true;
		else if (((x1==0)&&(y1==3)&&(x2==1)&&(y2==3))||((x1==1)&&(y1==3)&&(x2==0)&&(y2==3))) //(0,3), (1,3)
			value = true;
		else if (((x1==1)&&(y1==3)&&(x2==2)&&(y2==3))||((x1==2)&&(y1==3)&&(x2==1)&&(y2==3))) //(1,3), (2,3)
			value = true;
		else if (((x1==2)&&(y1==4)&&(x2==3)&&(y2==4))||((x1==3)&&(y1==4)&&(x2==2)&&(y2==4))) //(2,4), (3,4)
			value = true;
		else if (((x1==3)&&(y1==4)&&(x2==4)&&(y2==4))||((x1==4)&&(y1==4)&&(x2==3)&&(y2==4))) //(3,4), (4,4)
			value = true;
		else if (((x1==1)&&(y1==5)&&(x2==3)&&(y2==5))||((x1==3)&&(y1==5)&&(x2==1)&&(y2==5))) //(1,5), (3,5)
			value = true;
		else if (((x1==3)&&(y1==5)&&(x2==5)&&(y2==5))||((x1==5)&&(y1==5)&&(x2==3)&&(y2==5))) //(3,5), (5,5)
			value = true;
		else if (((x1==4)&&(y1==3)&&(x2==5)&&(y2==3))||((x1==5)&&(y1==3)&&(x2==4)&&(y2==3))) //(4,3), (5,3)
			value = true;
		else if (((x1==5)&&(y1==3)&&(x2==6)&&(y2==3))||((x1==6)&&(y1==3)&&(x2==5)&&(y2==3))) //(5,3), (6,3)
			value = true;
		else if (((x1==0)&&(y1==6)&&(x2==3)&&(y2==6))||((x1==3)&&(y1==6)&&(x2==0)&&(y2==6))) //(0,6), (3,6)
			value = true;
		else if (((x1==3)&&(y1==6)&&(x2==6)&&(y2==6))||((x1==6)&&(y1==6)&&(x2==3)&&(y2==6))) //(3,6), (6,6)
			value = true;
		
		return value;
	}
	
	
	public static void main(String[] args){
		MainFrame mf = new MainFrame();
		mf.setDefaultCloseOperation(EXIT_ON_CLOSE);
		mf.setBounds(50,50,1100,520);
		mf.setVisible(true);
	}
	
}
